/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pe.edu.unmsm.pacis.shca.domain.entity;

import java.io.Serializable;
import java.util.Date;
import java.util.List;
import javax.persistence.*;

/**
 *
 * @author solriver
 */
@Entity
@Table(name = "persona", catalog = "bdshca")
@NamedQueries({
    @NamedQuery(name = "Persona.findAll", query = "SELECT p FROM Persona p"),
    @NamedQuery(name = "Persona.findByIdPersona", query = "SELECT p FROM Persona p WHERE p.idPersona = :idPersona"),
    @NamedQuery(name = "Persona.findByPerNombres", query = "SELECT p FROM Persona p WHERE p.perNombres = :perNombres"),
    @NamedQuery(name = "Persona.findByPerApellidoPaterno", query = "SELECT p FROM Persona p WHERE p.perApellidoPaterno = :perApellidoPaterno"),
    @NamedQuery(name = "Persona.findByPerApellidoMaterno", query = "SELECT p FROM Persona p WHERE p.perApellidoMaterno = :perApellidoMaterno"),
    @NamedQuery(name = "Persona.findByPerCodigoDocumento", query = "SELECT p FROM Persona p WHERE p.perCodigoDocumento = :perCodigoDocumento"),
    @NamedQuery(name = "Persona.findByPerSexo", query = "SELECT p FROM Persona p WHERE p.perSexo = :perSexo"),
    @NamedQuery(name = "Persona.findByPerEdad", query = "SELECT p FROM Persona p WHERE p.perEdad = :perEdad"),
    @NamedQuery(name = "Persona.findByPerFechaNacimiento", query = "SELECT p FROM Persona p WHERE p.perFechaNacimiento = :perFechaNacimiento")})
public class Person implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @Column(name = "id_persona")
    private Integer id;
    @Column(name = "per_nombres")
    private String name;
    @Column(name = "per_apellido_paterno")
    private String lastName;
    @Column(name = "per_apellido_materno")
    private String secondLastName;
    @Column(name = "per_codigo_documento")
    private String documentCode;
    @Column(name = "per_sexo")
    private Character sex;
    @Column(name = "per_edad")
    private String age;
    @Column(name = "per_fecha_nacimiento")
    @Temporal(TemporalType.DATE)
    private Date birthDate;
    @OneToOne(cascade = CascadeType.ALL, mappedBy = "person")
    private User user;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "mother")
    private List<Member> motherSons;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "father")
    private List<Member> fatherSons;
    @JoinColumn(name = "tdo_id_tipo_documento", referencedColumnName = "id_tipo_documento")
    @ManyToOne(optional = false)
    private DocumentType documentType;
    @JoinColumn(name = "id_persona", referencedColumnName = "id_miembro", insertable = false, updatable = false)
    @OneToOne(optional = false)
    private Member member;

    public Person() {
    }

    public Person(Integer id) {
        this.id = id;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getPerNombres() {
        return name;
    }

    public void setPerNombres(String perNombres) {
        this.name = perNombres;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public String getSecondLastName() {
        return secondLastName;
    }

    public void setSecondLastName(String secondLastName) {
        this.secondLastName = secondLastName;
    }

    public String getDocumentCode() {
        return documentCode;
    }

    public void setDocumentCode(String documentCode) {
        this.documentCode = documentCode;
    }

    public Character getSex() {
        return sex;
    }

    public void setSex(Character sex) {
        this.sex = sex;
    }

    public String getAge() {
        return age;
    }

    public void setAge(String age) {
        this.age = age;
    }

    public Date getBirthDate() {
        return birthDate;
    }

    public void setBirthDate(Date birthDate) {
        this.birthDate = birthDate;
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public List<Member> getMotherSons() {
        return motherSons;
    }

    public void setMotherSons(List<Member> motherSons) {
        this.motherSons = motherSons;
    }

    public List<Member> getFatherSons() {
        return fatherSons;
    }

    public void setFatherSons(List<Member> fatherSons) {
        this.fatherSons = fatherSons;
    }

    public DocumentType getDocumentType() {
        return documentType;
    }

    public void setDocumentType(DocumentType documentType) {
        this.documentType = documentType;
    }

    public Member getMember() {
        return member;
    }

    public void setMember(Member member) {
        this.member = member;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Person)) {
            return false;
        }
        Person other = (Person) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "pe.edu.unmsm.pacis.shca.domain.entity.Person[ id=" + id + " ]";
    }
    
}
